<template>
  <div>

    <el-row>
      <el-col :span="24" id="Order1">

        <div id="Order2">

        </div>

        <div style="height: 20px;"></div>
        <el-table :data="page.records" border>

          <el-table-column prop="orderNum" label="订单ID" width="115">
          </el-table-column>

          <el-table-column prop="price" label="订单总价" width="130">
          </el-table-column>
          <el-table-column prop="userId" label="下单id" width="130">
          </el-table-column>
          <el-table-column prop="createTime" label="订单生成时间" width="130">
          </el-table-column>
          <el-table-column prop="payTime" label="订单支付时间" width="130">
          </el-table-column>
          <el-table-column prop="name" label="订单收件人" width="130">
          </el-table-column>
          <el-table-column prop="phoneNum" label="订单收件电话" width="130">
          </el-table-column>
          <el-table-column prop="addressName" label="订单收件地址" width="130">
          </el-table-column>

          <el-table-column prop="orderState" label="类型状态" width="130">
            <template slot-scope="scope">
              <template v-if="scope.row.orderState == 0">
                未支付
              </template>
              <template v-if="scope.row.orderState == 1">
                已支付
              </template>
              <template v-if="scope.row.orderState == 2">
                已取消
              </template>
              <template v-if="scope.row.orderState == 3">
                已退款
              </template>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="150">
            <template #default="scope">

              <el-button @click="disableType(scope.row.coachTypeId)" v-if="scope.row.coachTypeState == '1'" type="text"
                size="small">禁用</el-button>
              <el-button @click="enableType(scope.row.coachTypeId)" v-if="scope.row.coachTypeState == '0'" type="text"
                size="small">启用</el-button>

            </template>
          </el-table-column>

        </el-table>

        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="page.pageNum" :page-sizes="[1, 2, 3, 5]" :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="page.total">
        </el-pagination>

      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "OrderManagement",
    data() {
      return {
        page: {},
        param: {
          pageNum: 1,
          pageSize: 5,
        },
      }
    },
    methods: {
      enableType(coachTypeId) {
        this.$http.get("/account/yCoachType/enable", {
          params: {
            coachTypeId: coachTypeId
          }
        }).then(resp => {
          this.$message({
            message: resp.data.msg,
            type: 'success'
          });
          this.loadAllOrder();
        });
      },
      disableType(coachTypeId) {
        this.$http.get("/account/yCoachType/disable", {
          params: {
            coachTypeId: coachTypeId
          }
        }).then(resp => {
          this.$message({
            message: resp.data.msg,
            type: 'success'
          });
          this.loadAllOrder();
        });
      },
      handleSizeChange(val) {
        this.param.pageSize = val;
        this.loadAllOrder();
      },
      handleCurrentChange(val) {
        this.param.pageNum = val;
        this.loadAllOrder();
      },
      loadAllOrder() {
        this.$http.get("/order/yGoodsOrder/loadPageGoodsOrder", {
          params: {
            pageNum: this.param.pageNum,
            pageSize: this.param.pageSize
          }
        }).then(resp => {
          this.page = resp.data.data;
        })
      }
    },
    created() {
      this.loadAllOrder();
    }
  }
</script>

<style>
  #Order2 {
    margin-left: -520px;
    line-height: 100%;
    width: 100%
  }

  #Order1 {
    line-height: 100%;
    width: 100%
  }
</style>
